﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMSGSC.DAL;
using PMSGSC.BLL;

namespace PMSGSC.App
{
    public partial class ucLoadMaker : UserControl
    {
        public ucLoadMaker()
        {
            InitializeComponent();
        }
        public bool isChanges;
        private void txtCode_Validating(object sender, CancelEventArgs e)
        {
            if (txtCode.Text != "")
            {

                Maker maker = Maker_BLL.GetDataByCode(txtCode.Text, frmMain.ship.Ship_ID);
                if (null == maker)
                {
                    XtraMessageBox.Show("Maker not exits!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    e.Cancel = true;
                }
                else
                {
                    txtCode.Text = maker.CodeMaker;
                    txtName.Text = maker.NameMaker;
                    lb_id.Text = maker.Maker_ID.ToString();
                }
            }
            else
            {
                txtCode.Text = "";
                txtName.Text = "";
                lb_id.Text = "";
            }
        }
        public void SetValue(string code, string name, string id)
        {
            txtCode.Text = code;
            txtName.Text = name;
            lb_id.Text = id;
        }
                
        private void txtName_Validating(object sender, CancelEventArgs e)
        {
            if (txtName.Text != "")
            {
                Maker maker = Maker_BLL.GetDataByName(txtName.Text, frmMain.ship.Ship_ID);
                if (null == maker)
                {
                    XtraMessageBox.Show("Maker not exits!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    e.Cancel = true;
                }
                else
                {
                    txtCode.Text = maker.CodeMaker;
                    txtName.Text = maker.NameMaker;
                    lb_id.Text = maker.Maker_ID.ToString();
                }
            }
            else
            {
                txtCode.Text = "";
                txtName.Text = "";
                lb_id.Text = "";
            }
        }

        private void txtName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            frmGridMaker frmMaker = new frmGridMaker();
            frmMaker.ShowDialog();
            if (null != frmMaker.maker)
            {
                txtCode.Text = frmMaker.maker.CodeMaker;
                txtName.Text = frmMaker.maker.NameMaker;
                lb_id.Text = frmMaker.maker.Maker_ID.ToString();
                isChanges = true;
            }
        }
    }
}
